// 用户状态
import { userAccountLogin } from '@/api/user'
import { Message } from '@/components/Message/index'
export default {
  namespaced: true,
  state: () => ({
    profile: {
      id: '',
      account: '',
      nickname: '',
      avatar: '',
      token: '',
      mobile: ''
    }

  }),
  mutations: {
    setUser (state, val) {
      state.profile = val
    },
    cler (state, val) {
      state.profile = {}
    }
  },
  actions: {
    getObj (ctx, obj) {
      return new Promise((resolve, reject) => {
        userAccountLogin(obj).then(res => {
          ctx.commit('setUser', res.result)
          resolve()
        }).catch(() => {
          Message({ type: 'error', text: '账号密码有误' })
        })
      })
    }
  }
}
